#include <iostream>
#include <fstream>
using namespace std;
#include <stdlib.h>
#include <conio.h>

#include "vectr.h"
#include "player.h"
#include "scriptenginestate.h"
#include "scriptfunctions.h"
#include "scriptdata.h"
#include "mapscriptreader.h"
#include "scriptcompiler.h"
#include "scriptmanagefunction.h"

void drawWorld(Player p, int width, int height)
{
	system("cls");
	for(int row = 0; row < height; ++row)
	{
		for(int col = 0; col < width; ++col)
		{
			if(p.x == col && p.y == row)
			{
				cout << (char)p.icon;
			}
			else
			{
				cout << ".";
			}
		}
		cout << endl;
	}
}

int main()
{
	int width, height;
	readMapSize(width, height, "mapinfo.txt");
	ScriptEngine turingmachine;
	turingmachine.instructions = getByteCodeForScript("script.txt");
	turingmachine.index = 0;
	Player p;
	p.x = 5;
	p.y = 5;
	p.icon = 1;
	char input = 0;

	getch();

	while(input != 'q')
	{
		drawWorld(p, width, height);
		input = getch();
		if(input == ' ' && turingmachine.index < turingmachine.instructions->getSize())
		{
			runScript(p, turingmachine);
		}
		else
		{
			p.move(input);
		}
	}
	return 0;
}
